<template>
	<view>
		<view class="balance">
			<view class="text1">
				可提现金额（元）
			</view>
			<view class="text2">
				{{AmountOfMoney}}
			</view>
		</view>
		<view class="cu-list menu card-menu margin-top" style="width: 100%; border-bottom: 2rpx solid #E5E5E5;" @tap="Getabankcard">
			<view class="cu-item arrow" data-page_name="store_settlement">
				<view class="content">
					<text class="menu-name menu-name1" v-if="!isshow">{{Bankname}}（尾号{{Bankcardnumber}}）</text>
					<text class="menu-name menu-name1" v-if="isshow">请选择银行卡</text>
				</view>
			</view>
		</view>
		<view class="withdrawal">
			<text class="withdrawal-text1">￥</text>
			<input type="text" value="" placeholder="请输入提现金额" class="inp" v-model="cash"/>
			<view class="withdrawal1">
				<text class="withdrawal-text2" @tap="Allwithdrawals">全部提现</text>
			</view>
		</view>
		<button class="but" @tap="immediately">立即提现</button>
	</view>
</template>

<script>
	import {withdrawalBalance,userBalance,getRepeatToken} from '@/api/index.js'
	export default {
		data() {
			return {
				AmountOfMoney: 0.00,//余额
				Bankname: '',//银行卡名称
				Bankcardnumber: '',//银行卡尾号
				cash: '',//提现金额
				BankcardID: '',//银行卡id
				isshow: false,
				RepeatToken: '',
				javascrIpt: true //防止重复提交
			}
		},
		onLoad() {
			if( uni.getStorageSync('bankName') != ''){
				this.Bankname = uni.getStorageSync('bankName')
				this.Bankcardnumber = uni.getStorageSync('bankNumber')
				console.log(this.Bankcardnumber,uni.getStorageSync('bankNumber'))
				this.BankcardID = uni.getStorageSync('bankId')
			}else {
				this.isshow = true
			}
			userBalance({}).then(res=>{
				this.AmountOfMoney = res
			})
			getRepeatToken({}).then(res=>{
				this.RepeatToken = res
			})
		},
		methods: {
			//全部提现
			Allwithdrawals() {
				this.cash = this.AmountOfMoney
			},
			//选择银行卡
			Getabankcard() {
				uni.redirectTo({
					url: 'my_bank_card?id=-1'
				})
			},
			//立即提现
			immediately() {
				let data = {
					bankId: this.BankcardID,
					moneyStr: this.cash,
					repeatToken: this.RepeatToken
				}
				console.log(data)
				if(this.Verification(this.cash,this.AmountOfMoney)) {
					if(this.javascrIpt) {
						this.javascrIpt=false
						withdrawalBalance(data).then(res=>{
							if(res==null) {
								uni.showToast({
									title: '提交中',
									icon: 'loading',
									duration: 2000,
									success:function (){
										uni.redirectTo({
											url: './card/submit_review'
										})
									}
								})
							}
						})
					}
					
				}
				
			},
			Verification(cash,AmountOfMoney) {
				if(cash === '') {
					this.$api.msg('请输入提现金额');
					return false
				}
				if(cash > AmountOfMoney) {
					this.$api.msg('请输入正确金额');
					return false
				}
				if(cash <= 0) {
					this.$api.msg('请输入正确金额');
					return false
				}
				return true
			}
		}
	}
</script>

<style>
	@import "../../static/css/me.css";
	page {
		background: #F5F5F5;
	}
	.balance {
		padding-left: 30rpx;
		background: #fff;
		margin-top: 4rpx;
	}
	.balance .text1 {
		color: rgba(121, 121, 121, 1);
		font-size: 28rpx;
		text-align: left;
		font-family: Arial;
		padding-top: 14rpx;
	}
	.balance .text2 {
		color: rgba(16, 16, 16, 1);
		font-size: 28rpx;
		text-align: left;
		font-family: Arial;
		margin: 2rpx 0 12rpx 0; 
		padding-bottom: 12rpx;
	}
	.cu-list.card-menu {
		margin: 0 !important;
		border-radius: 0 !important;
	}
	.menu-name1 {
		color: rgba(16, 16, 16, 1);
		font-size: 28rpx;
		font-family: Arial;
	}
	.withdrawal {
		background: #fff;
		padding: 0 0 13rpx 24rpx;
		position: relative;
	}
	.withdrawal .withdrawal-text1 {
		color: rgba(121, 121, 121, 1);
		font-size: 60rpx;
		font-family: Arial;
	}
	.withdrawal .inp {
		width: 400rpx;
		height: 60rpx;
		color: rgba(136, 136, 136, 1);
		font-size: 28rpx;
		text-align: left;
		font-family: Microsoft Yahei;
		position: absolute;
		top: 12rpx;
		left: 100rpx;
	}
	.withdrawal .withdrawal1 {
	/* 	width: 134rpx; */
		height: 60rpx;
		text-align: center;
		border-left: 4rpx solid #D8D8D8;
		position: absolute;
		top: 16rpx;
		right: 0;
	}
	.withdrawal .withdrawal1 .withdrawal-text2 {
		color: rgba(255, 32, 59, 1);
		line-height: 60rpx;
		font-size: 28rpx;
		font-family: Arial;
		padding: 0 26rpx;
	}
	.but {
		width: 600rpx;
		height: 80rpx;
		background: #FF2F41;
		color: rgba(255, 255, 255, 1);
		font-size: 32rpx;
		font-family: PingFangSC-regular;
		border-radius:40rpx ;
		border: none !important;
		position: absolute;
		top: 504rpx;
		left: 64rpx;
	}
</style>
